﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<BA2009.Entities.Banner>>" %>

<%@ Import Namespace="MvcContrib.UI.Grid" %>
<%@ Import Namespace="MvcContrib.UI.Grid.ActionSyntax" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <link href="../../media/css/jtable.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/StyleSheet.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/jquery.cluetip.css" rel="stylesheet" type="text/css" />
    <link href="../../media/css/confirm.css" rel="stylesheet" type="text/css" />
    
    
    
    <script src="../../media/js/jTable-Customize.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.dimensions-1.2.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.cluetip.js" type="text/javascript"></script>
    <script src="../../media/js/jquery.simplemodal.js" type="text/javascript"></script>
    
    <script type="text/javascript">
        $(document).ready(function() {

            createTable();
            
        }
        );
        
        
    </script>
    
    
    <script type="text/javascript">
        $(document).ready(function() {

            $(".actions").each(function() {
                var btn = $(this).find(".delete");

                $(this).find(".delete").click(function(e) {
                    e.preventDefault();
                    var msg = $(this).attr("title")
                    var selectedId = $(this).attr("id")

                    var selectedRow=   $(this).parent().parent().parent();

                    confirm("Bạn có muốn xóa Banner " + msg + "?", function() {
                        deleteRow(selectedRow, btn, selectedId);
                    });
                 

                });
            });
        });

        function deleteRow(row, args,id) {

            var url = "/Banners/Delete/" + id;

            $.post(url, null,
                function(data) {
                    removeRow(row,data);
                    
                }
            , "json");

            return true;
        }

        function removeRow(row,data) {
            if (data == true) {
                row.remove();
            }
            else {
                alert("Xóa thất bại, vui lòng thử lại.");
            }
        }

     

        function confirm(message, callback) {
            $('#confirm').modal({
                close: false,
                overlayId: 'confirmModalOverlay',
                containerId: 'confirmModalContainer',
                onShow: function(dialog) {
                    dialog.data.find('.message').append(message);

                    // if the user clicks "yes"
                    dialog.data.find('.yes').click(function() {
                        // call the callback
                        if ($.isFunction(callback)) {
                            callback.apply();
                        }
                        // close the dialog
                        $.modal.close();
                    });
                }
            });
        }
                            
</script>

    <h2>Danh sách Banner</h2>

    
    
     <div id="search_container">
        
        <% Html.Grid(Model).Columns(column =>
        {

            column.For(c => c.BannerID).Named("ID");
            column.For(c => c.Code).Named("Mã");
            column.For(c => c.BannerName).Named("Tên");
            column.For(c => c.BannerID).Named("Thao tác").Action(banner =>
                {%> 
                    <td class="actions" id="row<%= banner.BannerID %>">
                        <a href="/Banners/Edit/<%= banner.BannerID %>"> <img src="../../media/images/edit.png" style="border-width: 0px;" alt="Thay đổi" class="edit" /> </a> 
                         <a href="#"> <img src="../../media/images/delete.png" style="border-width: 0px;" id="<%=banner.BannerID %>" title="<%=banner.Code %>"  alt="Xóa" class="delete" /> </a> 
                        
                    </td>
                <%}
            );
        })
        .RowAttributes(row=>new MvcContrib.Hash(id=>"tablerow"+row.Item.BannerID))
        .Attributes(id => "search_datatable")
        .Render();
            
     
        %>
        
            <div id='confirm' style='display:none'>
	                            <a href='#' title='Close' class='modalCloseX modalClose'>x</a>
	                            <div class='header'><span>Xác nhận</span></div>
	                            <p class='message'></p>
	                            <div class='buttons'>
	                            <div class='no modalClose'>Không</div><div class='yes'>Có</div>
            </div>

     </div>
     
   
    <p>
        <%= Html.ActionLink("Create New", "Create") %>
    </p>

</asp:Content>

<%-- <readZ:JavaScriptManagerProxy id="scriptManagerProxy" runat="Server">
        <Scripts>
            <readZ:JavaScriptReference Path="~/Scripts/dummyObject.js"/>
        </Scripts>
        <OnPageLoad>
            dummyObject.init();
        </OnPageLoad>
        <OnPageUnload>
            alert('Cleanup for content page.');
        </OnPageUnload>
    </readZ:JavaScriptManagerProxy>--%>